package database;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.Cinema;

/**
 * 
 * @author Patrick
 *
 */

public class DBCinema 
{	
	private DBConnection con;
	
	public DBCinema()
	{
		con = DBConnection.getInstance();
	}
	
	public void createCinema(Cinema cin)
	{
		String cinNumber = cin.getNumber();
		String cinDescription = cin.getDescription();
		String query = String.format("Insert INTO Cinema Values ('%s', '%s')", 
				cinNumber, cinDescription);
		con.execute(query);
	}
	
	public Cinema getCinema(String cinNum)
	{
		Cinema result = null;
		String condition = ("Select number, description from Cinema where number = " + cinNum);
		ResultSet resSet = con.executeResSet(condition);
		try {
			resSet.next();
			String number = resSet.getString("number");
			String description = resSet.getString("description");
			result = new Cinema(number, description);
			resSet.getStatement().close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
}
